<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<div class="easyui-panel" title="商品详情" data-options="fit:true">
    <form class="itemForm" id="itemAddForm" name="itemAddForm" method="post">
        <table style="width:100%;">
            <tr>
                <td class="label">商品类目：</td>
                <td>
                    <input id="cid" name="cid" style="width:200px;">
                </td>
            </tr>
            <tr>
                <td class="label">商品标题：</td>
                <td>
                    <input class="easyui-textbox" type="text" id="title" name="title"
                           data-options="required:true" style="width:100%">
                </td>
            </tr>
            <tr>
                <td class="label">商品卖点：</td>
                <td>
                    <input class="easyui-textbox" type="text" id="sellPoint" name="sellPoint"
                           data-options="validType:'length[0,150]',multiline:true" style="width:100%;height:60px;">
                </td>
            </tr>
            <tr>
                <td class="label">商品价格：</td>
                <td>
                    <input class="easyui-numberbox" type="text" id="priceView" name="priceView"
                           data-options="required:true,min:0,precision:2">
                    <input type="hidden" id="price" name="price">
                </td>
            </tr>
            <tr>
                <td class="label">商品库存：</td>
                <td>
                    <input class="easyui-numberbox" type="text" id="num" name="num"
                           data-options="required:true,min:0,precision:0">
                </td>
            </tr>
            <tr>
                <td class="label">条形码：</td>
                <td>
                    <input class="easyui-textbox" type="text" id="barcode" name="barcode"
                           data-options="validType:'length[0,30]'">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <!-- 加载编辑器的容器 -->
                    <script id="container" name="itemDesc" type="text/plain">商品描述</script>
                </td>
            </tr>

            <tr class="paramsShow" style="display:none;">
                <td class="label">商品规格：</td>
                <td>

                </td>
            </tr>

            <tr>
                <td colspan="2">
                    <button onclick="submitForm()" class="easyui-linkbutton" type="button"
                            data-options="iconCls:'icon-ok'">保存
                    </button>
                    <button onclick="clearForm()" class="easyui-linkbutton" type="button"
                            data-options="iconCls:'icon-undo'">重置
                    </button>
                </td>
            </tr>
        </table>
        <input name="paramData" id="paramData" style="display:none;">
    </form>
</div>
<script>
    //保存按钮
    function submitForm() {
        $('#itemAddForm').form('submit',{
            url:'item',
            //提交前控件校验，返回false 无法提交
            onSubmit:function () {
                //将前台的元转换成分保存到数据库
                $('#price').val($.trim($('#priceView').val())*100);
                //当所有控件验证成功后  返回ture 否则返回false
                return $(this).form('validate');
            },
            success:function (data) {
                if(data>0){
                    $.messager.alert('温馨提示','商品添加成功！！','info');
                    myShop.addTab('查询商品','item-list');
                }
            }
        })
    }

    //实例化富文本编辑器
    UE.getEditor('container');
    //
    $(function(){
        //加载商品类别
        $('#cid').combotree({
            url:'itemCat?parentId=0',
            required:true,
            onBeforeSelect:function (node) {
                var isLeaf = $('#cid').tree('isLeaf',node.target);
                if(!isLeaf){
                    $.messager.alert('警告','请选择最终分类！','info');
                    return false;
                }
            },
            onBeforeExpand:function (node) {
                //获取树控件的属性
                var options = $('#cid').combotree('tree').tree('options');
                options.url = 'itemCat?parentId=' + node.id;
            }
        });

    });
</script>